import { Injectable, signal } from '@angular/core';

export interface Note {
  id: string;
  content: string;
  x: number;
  y: number;
  width: number;
  height: number;
  color?: string;
}

@Injectable({
  providedIn: 'root'
})
export class NotesService {
  private _notes = signal<Note[]>([]);

  readonly notes = this._notes.asReadonly();

  addNote(note: Note) {
    this._notes.update(notes => [...notes, note]);
  }

  updateNote(id: string, updates: Partial<Note>) {
    this._notes.update(notes =>
      notes.map(note =>
        note.id === id ? { ...note, ...updates } : note
      )
    );
  }

  removeNote(id: string) {
    this._notes.update(notes => notes.filter(note => note.id !== id));
  }

  clearNotes() {
    this._notes.set([]);
  }
}
